/**
 * @file TcpClient.h
 * @author yangx (yangxing2297@163.com)
 * @brief tcp客户端的封装的接口类
 * @version 0.1
 * @date 2023-04-07
 * 
 * @copyright Copyright (c) 2023
 * 
 */
#ifndef _TCP_CLIENT_H_
#define _TCP_CLIENT_H_
#include <string>
#include <cstdint>
#include <functional>


class CTcpClient;
class CTcpClientImpl;

enum ClientStatus
{
    Init = 0,       // 初始化
    Connected,      // 已连接
    Closed,         // 连接被关闭
    Timeout,        // 超时
    ReadEof,        // 读取到EOF
    Reading,        // 正在读取
    Writing,        // 正在写入
    Error           // 出现错误
};

// tcp连接的状态回调，断开和错误等处理的回调.
using StatusCB = std::function<void (ClientStatus)>;
// 接收到数据的回调函数.
using ReadMsgCB = std::function<void (char * const, uint32_t)>;


class CTcpClient
{
public:
    CTcpClient(ReadMsgCB readMsgCB, StatusCB statusCB=nullptr) { };
    virtual ~CTcpClient() {}

    virtual bool Connect(const std::string &dstIp, const uint16_t &port, const int &reTimeval=0) = 0;

    virtual bool Run() = 0;

    virtual bool SetReadMsgCB(ReadMsgCB msgCB) = 0;
    virtual bool SetStatusCB(StatusCB statusCB) = 0;

    virtual bool SendMsg(const std::string &msg) = 0;

};

#endif /// _TCP_CLIENT_H_